-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat(perps): new TPSL view design #21396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
|
I noticed that the gap between SL clear button and TP Expected profit section becomes very small when the keyboard is open. Simulator.Screen.Recording.-.iPhone.16.Pro.-.2025-10-21.at.12.29.55.mp4 |
| effectiveEntryPrice = spotPrice; | ||
| } else { | ||
| effectiveEntryPrice = livePrice || initialCurrentPrice || 0; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Entry Price Handling Regression
The effectiveEntryPrice calculation in PerpsTPSLView.tsx no longer correctly handles position.entryPrice values of "0" or "0.00". The previous logic would fall back to other price sources in these cases, but the updated code now uses 0 as the effective entry price, which can lead to incorrect calculations.
| // Notional value must be positive for fee calculation (use abs for short positions) | ||
| const tpNotionalValue = | ||
| takeProfitPrice && positionSizeForPnL !== 0 | ||
| ? (parseFloat(takeProfitPrice) * Math.abs(positionSizeForPnL)).toFixed(2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Non-numeric Prices Cause Fee Calculation Errors
When takeProfitPrice or stopLossPrice contain non-numeric characters, parseFloat returns NaN. This causes tpNotionalValue and slNotionalValue to become the string "NaN" after toFixed(2). Passing "NaN" as the amount to usePerpsOrderFees may lead to incorrect fee calculations for expected P&L.
Additional Locations (1)
|




Description
This PR implements TAT-1729, adding expected profit/loss calculation display to the Auto Close (TP/SL) configuration screen. It also includes several UX improvements based on design refinements.
What is the reason for the change?
Users need to see the expected net profit or loss when setting TP/SL values, accounting for trading fees. This helps them make informed decisions about their risk management strategy. Additionally, several UX improvements were needed to match the final design specifications.
What is the improvement/solution?
Expected P&L Display: Shows real-time expected profit/loss below TP and SL input fields
formatPerpsFiatwith PRICE_RANGES_MINIMAL_VIEWTerminology Update: Renamed "TP/SL" to "Auto close" throughout the UI
UX Improvements:
Implementation Approach (DRY):
calculatePnL()utility frompnlCalculations.tsusePerpsOrderFees()hook for accurate fee calculationcalculatePositionSize()for new orderscalculateExpectedPnL()wrapper that combines P&L with fee deductionusePerpsTPSLFormhook return values (no new hooks created)formatPerpsFiat)Changelog
CHANGELOG entry: Added expected profit/loss display to Auto Close (TP/SL) configuration showing net profit after fees, improved UI layout and terminology
Related issues
Manual testing steps
Screenshots/Recordings
Before
After
Screen.Recording.2025-10-18.at.7.43.52.PM.mov
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Displays fee-adjusted expected profit/loss in the TPSL view, passes needed params from Order view, and updates layout/strings and validations.
calculateExpectedPnL,usePerpsOrderFees, andcalculatePositionSize; added tousePerpsTPSLForm(expectedTakeProfitPnL,expectedStopLossPnL).PerpsOrderViewnow passesamountandszDecimalstoRoutes.PERPS.TPSL; nav types extended.$label moved left of inputs; non-sticky percentage buttons.calculateExpectedPnLinutils/pnlCalculations.tpslValidation(direction checks, mixed sign handling).cancel,set,clear,expected_profit/loss.usePerpsTPSLUpdate.Written by Cursor Bugbot for commit 4ac0c9d. This will update automatically on new commits. Configure here.